﻿using Ken_WPF_UI.Data;
using Ken_WPF_UI.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace Ken_WPF_UI.View
{
    /// <summary>
    /// DataGridWindow.xaml 的交互逻辑
    /// </summary>
    public partial class DataGridWindow : Window
    {
        public DataGridWindow()
        {
            InitializeComponent();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            List<UserInfo> userInfos = UserData.GetUserList();
            List<DeptInfo> deptInfos = UserData.GetDeptList();


            //因为标签中指定了SelectedValuePath 和 DisplayMemberPath 的值 所以下面不需要代码指定

            //方式1.1  绑定ItemsSource
            //datagrid1.ItemsSource = userInfos;
            //deptCol.ItemsSource = deptInfos;


            //方式1.1 绑定ItemsSource  指定Column绑定ItemsSourc
            datagrid1.ItemsSource = userInfos;
            DataGridComboBoxColumn dataGridColumn = datagrid1.Columns[3] as DataGridComboBoxColumn;
            dataGridColumn.ItemsSource = deptInfos;

            //方式2  绑定DataContext 一般可以是Window的DataContext 也可是 直接控件的DataContext 如DataGrid
            ViewModel.UserDeptViewModel userDeptViewModel = UserData.GetUserDeptViewModelt();
            datagrid2.DataContext = userDeptViewModel;
        }
    }
}
